<%@ page language="java" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	//List listOrd = (List) request.getAttribute("ord");//外层订单循环List<Bean>
	//Map mapItemOrd = (Map) request.getAttribute("itemOrd");//内层订单物品循环Map<String, List<Bean>>
	//List mapItemList = (List) request.getAttribute("allItem");//下拉键
%>
<html>
<head>

<script type="text/javascript"
	src="http://code.jquery.com/jquery-1.10.2.min.js">
	
</script>
<script type="text/javascript">
	var generateHideElement = function(name, value) {
		var tempInput = document.createElement("input");
		tempInput.type = "hidden";
		tempInput.name = name;
		tempInput.value = value;
		return tempInput;
	}

	function cngCnt(idOrd, idItem, oper) {
		var cntValue = $("#" + idOrd + "" + idItem);
		if ("add" == oper) {
			cntValue.val(parseInt(cntValue.val()) + 1);
		} else if ("mns" == oper) {
			if (cntValue.val() > 1) {
				cntValue.val(parseInt(cntValue.val()) - 1);
			}
		}
	}

	function delOrdItem(idOrd, idItem) {
		var fm = document.createElement("form");
		document.body.appendChild(fm);
		fm.method = 'post';
		fm.action = '/EggShell/delOrdItem';
		var ordId = generateHideElement("ordId", idOrd), itmId = generateHideElement(
				"itmId", idItem);
		fm.appendChild(ordId);
		fm.appendChild(itmId);
		fm.submit();
		fm.parentNode.removeChild(fm);
	}

	function saveOrd(ordId) {
		var inputs = $("#" + ordId).find("input");
		var expIdField = $("#exp" + ordId);
		var theJson = [];
		for (var i = 0; i < inputs.length; i++) {
			var params = [];
			theJson.push({
				"ordId" : ordId,
				"itmId" : inputs[i].name,
				"itmCnt" : inputs[i].value
			});
		}
		//theJson.push({"itmIds" : params});
		var theJsonStr = JSON.stringify(theJson);
		//alert(theJsonStr);
		var nForm = document.createElement("form");
		document.body.appendChild(nForm);
		nForm.method = 'post';
		nForm.action = '/EggShell/saveOrd';
		var ordId = generateHideElement("ordId", ordId), 
		itemIds = generateHideElement(
				"itmIdsJson", theJsonStr),
		expId = generateHideElement(
						"expId", expIdField.val());

		nForm.appendChild(ordId);
		nForm.appendChild(itemIds);
		nForm.appendChild(expId);

		nForm.submit();
		nForm.parentNode.removeChild(nForm);
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>蛋壳跨境电商-管理员</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>

	<img style="width: 50px; height: 50px"
		src="http://oim8ighi5.bkt.clouddn.com/test.jpg">
	<table style="border-collapse: separate; border-spacing: 0px 30px;">
		<tr>
			<th>订单号</th>
			<th>客户</th>
			<th>客源</th>
			<th>物品</th>
			<th>快递单号</th>
		</tr>
		<c:forEach items="${allOrd}" var="ord">
			<tr id="${ord.ordId}">
				<td style="text-align: center">${ord.ordId}</td>
				<td style="text-align: center">${ord.buyerNm}</td>
				<td style="text-align: center">${ord.buyerSrc}</td>
				<td style="text-align: center"><c:forEach
						items="${itemOrd[ord.ordId]}" var="listItem">
						<div>
							<label>${listItem.itmNm }</label> x<input
								id="${ord.ordId}${listItem.itmId}" name="${listItem.itmId}"
								value="${listItem.itmCnt }"
								style="width: 30px; text-align: center" />&nbsp;&nbsp;&nbsp;&nbsp;
							<button
								onclick="delOrdItem('${ord.ordId}' , '${listItem.itmId}')">删</button>
							&nbsp;&nbsp;&nbsp;&nbsp;
							<button
								onclick="cngCnt('${ord.ordId}' , '${listItem.itmId}' , 'mns')">-</button>
							&nbsp;&nbsp;&nbsp;&nbsp;
							<button
								onclick="cngCnt('${ord.ordId}' , '${listItem.itmId}' , 'add')">+</button>
							&nbsp;&nbsp;&nbsp;&nbsp;
						</div>
					</c:forEach></td>
				<td style="text-align: center"><input id="exp${ord.ordId}" value="${ord.expId}"
					style="width: 60px; text-align: center" /></td>
				<td>
					<button onclick="saveOrd('${ord.ordId}')">修改</button>
				</td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>